/**
 * Copyright (C) BFH www.bfh.ch 2011
 * Code written by: Patrick Dobler, Marc Folly
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
package ch.bfh.ti.kybernetik.gui.slick.components;

import javax.vecmath.Point2d;

import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Circle;

import ch.bfh.ti.kybernetik.engine.model.LightBulb;
import ch.bfh.ti.kybernetik.gui.slick.SlickRenderUtils;

/**
 * This Class renders a {@link LightBulb} instance
 * 
 */
public class LightBulbComponent implements SelectableSlickComponent<LightBulb> {
	private final LightBulb lightBulb;

	private float alphaColor = 0.7f;

	private boolean selected = false;

	public LightBulbComponent(LightBulb lightBulb) {
		this.lightBulb = lightBulb;
	}

	@Override
	public void render(GameContainer gc, Graphics g) throws SlickException {

		if (selected) {
			g.setColor(Color.white);
			SlickRenderUtils.drawCircle(g, lightBulb.getX(), lightBulb.getY(), 11);
			SlickRenderUtils.drawCircle(g, lightBulb.getX(), lightBulb.getY(), 12);
			SlickRenderUtils.drawCircle(g, lightBulb.getX(), lightBulb.getY(), 13);
		}
		g.setColor(SlickRenderUtils.getAlphaColor(Color.yellow, alphaColor));
		SlickRenderUtils.fillCircle(g, lightBulb.getX(), lightBulb.getY(), 10);
		SlickRenderUtils.drawCircle(g, lightBulb.getX(), lightBulb.getY(), lightBulb.getMaxRadius());
		g.drawString("Max I [" + lightBulb.getMaxIntensity() + "]", lightBulb.getX() - 50, lightBulb.getY() + 10);

	}

	public boolean intersectWithPoint(Point2d point) {
		Circle c = SlickRenderUtils.getCircle(lightBulb.getX(), lightBulb.getY(), 20);
		return c.contains((float) point.getX(), (float) point.getY());
	}

	@Override
	public void setSelected(boolean selected) {
		this.selected = selected;

	}

	@Override
	public boolean isSelected() {
		return selected;
	}

	@Override
	public void setX(double X) {
		this.lightBulb.setX((int) X);
	}

	@Override
	public void setY(double Y) {
		this.lightBulb.setY((int) Y);
	}

	@Override
	public LightBulb getModelObject() {
		return lightBulb;
	}

}
